package ar.edu.caece.compiler.grammar.factories;

import ar.edu.caece.compiler.error.ErrorManager;
import ar.edu.caece.compiler.error.ParsingException;
import ar.edu.caece.compiler.grammar.AbstractTokenVisitorFactory;
import ar.edu.caece.compiler.grammar.Recognizer;
import ar.edu.caece.compiler.grammar.TokenRecognizer;
import ar.edu.caece.compiler.grammar.TokenVisitor;
import ar.edu.caece.compiler.grammar.attributes.Attribute;

import ar.edu.caece.compiler.grammar.attributes.StringAttribute;
import ar.edu.caece.compiler.grammar.nonterminals.OP11;
import ar.edu.caece.compiler.grammar.terminals.SumaEnteroToken;

public class OP11Factory extends AbstractTokenVisitorFactory {

	private static OP11Factory INSTANCE;
	
	public static OP11Factory getInstance() {
		if(INSTANCE==null) INSTANCE = new OP11Factory();
		return INSTANCE;
	}
	
	private OP11Factory() {
		
	}
	
	@Override
	public TokenVisitor makeChainedVisitor(
			final TokenVisitor siguiente) throws Exception {
		return new SumaEnteroToken.SumaEnteroChainVisitor(siguiente) {
			
			@Override
			public Recognizer sumaEnteroCase(SumaEnteroToken llamador) {
				OP11 op11 = new OP11(llamador);
				op11.addAttribute("tipo", new StringAttribute("ENTERO"));
				op11.addAttribute(Attribute.OPERACION, new StringAttribute("SUMA"));

				return op11;
			}
		};
	
	}
	@Override
	public TokenVisitor makeVisitor() throws Exception {
		return new SumaEnteroToken.SumaEnteroTokenVisitor() {
			
			@Override
			public Recognizer defaultCase(TokenRecognizer llamador) throws Exception {
				ErrorManager.getInstance().manage(llamador,"OP11",new ParsingException("Error de parsing.",OP11.class,llamador));
				return null;
			}
			
			@Override
			public Recognizer sumaEnteroCase(SumaEnteroToken llamador) {
				OP11 op11 = new OP11(llamador);
				op11.addAttribute("tipo", new StringAttribute("ENTERO"));
				op11.addAttribute(Attribute.OPERACION, new StringAttribute("SUMA"));

				return op11;			
				}
		};
	}
	
	
}
